﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DatabaseUserTest
{
    public class DBUser
    {
        static DatabaseUserTest.DatabaseContext db = new DatabaseUserTest.DatabaseContext();

        public void AddUser(User user)
        {
            db.Users.Add(user);
            db.SaveChanges();   
        }

        public List<User> FindAllUsers()
        {

            List<User> users = new List<User>();
            var query = from u in db.Users
                            orderby u.Name
                            select u;

            foreach (var item in query)
            {
                users.Add(item);
            }
            return users;
                
        }

        public User FindUser(int phoneNo)
        {
            var query = from u in db.Users
                        select u;

            foreach (var item in query)
            {
                if (item.PhoneNo == phoneNo)
                {
                    return item;
                }
            }
            return null;
        }
        
    }
}
